package com.youko.customerfrontstage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youko.customerfrontstage.bean.Commodity;
import com.youko.customerfrontstage.bean.CommoditySpu;
import com.youko.customerfrontstage.mapper.CommodityMapper;
import com.youko.customerfrontstage.mapper.CommoditySpuMapper;
import com.youko.customerfrontstage.mapper.SkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * commodity的service层
 */
@Service
public class CommodityService {
    @Autowired
    CommodityMapper commodityMapper;
    @Autowired
    SkuMapper skuMapper;

    @Autowired
    CommoditySpuMapper commoditySpuMapper;

    /**
     * ，负责实现分页算法，调用mapper中的findall()方法
     * @param pageNum 页的开始位
     * @param pageSize 页的大小
     * @return 商品的集合
     */
    public PageInfo<CommoditySpu> findByPage(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<CommoditySpu> spus = skuMapper.findAllSpu();
        return new PageInfo<>(spus);
    }

    public Commodity selectById(int id){
        return commodityMapper.findCommodityById(id);
    }

    public CommoditySpu selectSpuById(int id){
        return commoditySpuMapper.getCommoditySpuById(id);
    }

    public List<Commodity> selectAll(){
        return commodityMapper.findAll();
    }

}
